﻿namespace dpa.Library.Helper;

public static class ExcelHelper
{
    public static int ConvertToNumber(string letters)
    {
        if (string.IsNullOrEmpty(letters))
            throw new ArgumentException("输入不能为空");

        letters = letters.ToUpper();
        int result = 0;

        for (int i = 0; i < letters.Length; i++)
        {
            char c = letters[i];
            if (c < 'A' || c > 'Z')
                throw new ArgumentException($"字符 '{c}' 不是有效的大写字母(A-Z)");

            int value = c - 'A';

            if (i < letters.Length - 1)
                result = (result + value + 1) * 26;
            else
                result += value;
        }

        return result;
    }
}